#!/bin/bash
websocket_port=8880
# add upload img's path

mkdir -p /data/shitouren/img/saved
mkdir -p /data/shitouren/img/failed
mkdir -p /data/shitouren/map/saved
mkdir -p /data/shitouren/map/failed

python -m compileall ./app

rm -rf ./test/shitouren
mkdir -p ./test/shitouren
mkdir -p ./test/shitouren/tasks
mkdir -p ./test/shitouren/utils
mkdir -p ./test/shitouren/config
mkdir -p ./test/shitouren/controls
mkdir -p ./test/shitouren/views
mkdir -p ./test/shitouren/views/cms
mkdir -p ./test/shitouren/test_script

mv ./app/shitouren.pyc  ./test/shitouren/test.pyc
mv ./app/*.pyc          ./test/shitouren/
mv ./app/tasks/*.pyc    ./test/shitouren/tasks
mv ./app/utils/*.pyc    ./test/shitouren/utils
mv ./app/config/*.pyc   ./test/shitouren/config
mv ./app/controls/*.pyc ./test/shitouren/controls
mv ./app/views/*.pyc    ./test/shitouren/views
mv ./app/views/cms/*.pyc    ./test/shitouren/views/cms
mv ./app/test_script/*.pyc     ./test/shitouren/test_script
# replace db instance with test
cp -f ./test/shitouren/controls/data_pool_mysql_test.pyc ./test/shitouren/controls/data_pool_mysql.pyc
cp -f ./test/shitouren/controls/mongo_test.pyc ./test/shitouren/controls/mongo.pyc
cp -f ./test/shitouren/config/environment_test.pyc ./test/shitouren/config/environment.pyc

ps aux | grep test.pyc | grep -v grep | awk '{print $2}' | xargs kill -9
#ps aux | grep socket_server.pyc | grep "port=${websocket_port}" | awk '{print $2}' | xargs kill -9

PYTHONPATH=./test/shitouren/ nohup python ./test/shitouren/test.pyc port=8000 >> /web/logs/test.log 2>&1 &
#nohup python ./test/shitouren/socket_server.pyc port=${websocket_port} &

tail -f /web/logs/test.log

